<script setup lang="ts">
const router = useRouter()

const isAgree = ref(false)

function handleLogin() {
  if (!isAgree.value) {
    uni.showToast({ title: '请先同意《服务协议》与《隐私政策》', icon: 'none' })
    return
  }

  window.open(
    'https://tongdadianzhao.tykhrs.site/index/wechat/bootToUrl',
    '_self',
  )
}

function handleViewProtocol(type: '用户协议' | '隐私政策') {
  router.push({
    name: 'protocol',
    params: { type },
  })
}
</script>

<template>
  <view class="fixed left-1/2 top-1/2 flex flex-col items-center -translate-x-1/2 -translate-y-250rpx">
    <image
      class="h-120rpx w-120rpx"
      src="@/static/images/logo.png"
    />
    <Spacer height="33" />
    <view class="text-34rpx text-#333333 font-bold leading-34rpx">
      欢迎登录通达电召
    </view>
  </view>
  <view class="fixed bottom-30rpx flex flex-col items-center x-center">
    <RGButton @tap="handleLogin">
      微信一键登录
    </RGButton>
    <Spacer height="40" />
    <view class="flex items-center" @tap="isAgree = !isAgree">
      <Checkbox :checked="isAgree" />
      <Spacer width="8" />
      <view class="text-26rpx text-#999999">
        我已阅读并同意
        <text class="text-#3F8BF6" @tap.stop="() => handleViewProtocol('用户协议')">
          《服务协议》
        </text>
        与
        <text class="text-#3F8BF6" @tap.stop="() => handleViewProtocol('隐私政策')">
          《隐私政策》
        </text>
      </view>
    </view>
  </view>
</template>

<route lang="yaml">
name: 'login'
style:
  navigationBarTitleText: '登录'
</route>
